/*
 * A simple ToDo Manager
 *
 * Copyright (c) 2011 Nosheen Zaza, Manuel Rebollo, Seyedsaeid Mahpeikar and
 * Wo Ke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package todomanager.ui.listview;

import java.awt.Component;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import todomanager.model.Task;
import todomanager.ui.tableview.TaskDisplayCellComponent;

/**
 * The renderer of {@code TaskDisplayList}. It uses a modified
 * {@code TaskDisplay} component to show the tasks.
 *
 * @author Nosheen Zaza
 */
public class TaskItemRenderer implements ListCellRenderer{

    TaskDisplayCellComponent taskDisplay;

    /**
     * Initializes a new instance.
     */
    public TaskItemRenderer() {
        taskDisplay = new TaskDisplayCellComponent();

        /*
         * Do not show the check box, it makes no sense to show a check box
         * that does not work.
         */
        taskDisplay.getCheckTextField().getCheckBox().setVisible(false);
    }

    /**
     * Returns a cell renderer.
     * @param list
     * @param value
     * @param index
     * @param isSelected
     * @param cellHasFocus
     * @return taskDisplay
     */
    public Component getListCellRendererComponent(JList list, Object value,
            int index, boolean isSelected, boolean cellHasFocus) {
        Task t = (Task) value;
        taskDisplay.updateData(t, isSelected);
        return taskDisplay;
    }

}
